home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / netprn.zip / NETPRNQU.PAS < prev    next >
Pascal/Delphi Source File  |  1992-10-05  |  7KB  |  218 lines

  1. {
  2.   Turbo Pascal Unit of Print Queue Services for NetWare
  3.   Version 1.0  10/2/92
  4.  
  5.   by Richard S. Sadowsky
  6.  
  7.   Please address questions and comments about this unit to ALL in section 6 of
  8.   the PCVENB forum on Compuserve.
  9. }
  10. {$S-,R-,V-,I-}
  11. unit NetPrnQue;
  12. interface
  13.  
  14. {$IFDEF Windows}
  15.   {$DEFINE WindowsOrDPMI}
  16. {$ELSE}
  17.   {$IFDEF DPMI}
  18.     {$DEFINE WindowsOrDPMI}
  19.   {$ENDIF}
  20. {$ENDIF}
  21. uses
  22. {$IFDEF Windows}
  23.   WinProcs,
  24.   WinTypes,
  25.   WinDos,
  26.   WinDPMI,
  27. {$ELSE}
  28.   Dos,
  29.   {$IFDEF DPMI}
  30.   WinDPMI,
  31.   {$ENDIF}
  32. {$ENDIF}
  33.   NetWare,
  34.   NetQue;
  35.  
  36. {$IFDEF Windows}
  37. type
  38.   Registers            = TRegisters;
  39. {$ENDIF}
  40.  
  41. const
  42.   DefaultCPP = 132;
  43.   DefaultLPP = 60;
  44.  
  45.   {print queue flags}
  46.   pqPrintBanner    = $80;    {when set, the banner page is printed}
  47.   pqText           = $40;    {when set, indicates tabs should be expanded}
  48.   pqNotify         = $10;    {when set, NetWare will notify station when done}
  49.   pqFormFeed       = $08;    {when set, suppresses the form feed added by NetWare}
  50.  
  51. type
  52.   PPrintQueClientRec = ^TPrintQueClientRec;
  53.   TPrintQueClientRec =
  54.     record
  55.       Dummy : Byte;   {server printer?}
  56.       TabSize : Byte; {1..18}
  57.       NumCopies : Word;                                {hi-lo}
  58.       Dummy2 : Byte;
  59.       Flags : Byte;   {Print flags:
  60.                          04h - print interrupted capture
  61.                          08h - Suppress auto form feed
  62.                          10h - Notify submitting station when done
  63.                          40h - Enable tab expansion
  64.                          80h - Print Banner page
  65.                        }
  66.       LinesPerPage : Word;                             {hi-lo}
  67.       ColsPerPage  : Word;                             {hi-lo}
  68.       Unknown : Array[1..22] of Char;
  69.       BannerName : Array[1..13] of Char;
  70.       UserName : Array[1..13] of Char;
  71.     end;
  72.  
  73. function GetPrinterQueue(LPTDevice : Byte; var printQueueID : LongInt) : Byte;
  74.   {-Undocumented NetWare function to obtain the print queue assigned to a
  75.     specific local LPT port (0=LPT1, 1=LP2, 2=LPT3). Returns 0 if successful.}
  76.  
  77. procedure MakeClientRecord(pTabSize : Byte; pNumCopies : Word; pFlags : Byte;
  78.                            pLinesPerPage : Word; pColsPerPage : Word;
  79.                            pBannerName : Str20; pUserName : String;
  80.                            var ClientArea : ClientRecordArea);
  81.   {-Given some printer parameters, this routine initializes the
  82.     ClientRecordArea of the JobEntryType. The information needed to write
  83.     this function appears to be undocumented. I obtained the info by reverse
  84.     engineering print jobs created by NetWare.
  85.  
  86.     pTabSize must be between 1..12 (18?)
  87.  
  88.     pNumCopies must be 1 or more
  89.  
  90.     pFlags can be any combination of:
  91.       pqPrintBanner    = $80; print banner
  92.       pqText           = $40; enables tab expansion
  93.       pqNotify         = $10; notifies the submitting workstation when done
  94.       pqFormFeed       = $08; Suppress form feed after form
  95.  
  96.     pLinesPerPage (not sure how this is used, pass zero here for default)
  97.  
  98.     pColsPerPage  (not sure how this is used, pass zero here for default)
  99.  
  100.     pBannerName is the name to appear in the banner. Only has meaning if the
  101.                 pqPrintBanner flag is set in pFlags.
  102.  
  103.      pUserName is the user name to appear in the banner. Only has meaning if
  104.               the pqPrintBanner flag is set in pFlags.
  105.  
  106.     ClientArea will be formatted correctly for a call to CreateQueueJobAndFile
  107.                (or our higher level replacement, AddFileToPrintQueue).
  108.   }
  109.  
  110. function AddFileToPrintQueue(QueueID : LongInt;
  111.                              var JobEntry : JobEntryType;
  112.                              FName : String) : Byte;
  113.   {-Adds the file specified by FName to the specified PrintQueue. JobEntry must
  114.     be properly initialized before the call. This call actually copies the
  115.     specified file into the print queue. Returns 0 on success, otherwise DOS or
  116.     NetWare error code.
  117.  
  118.     The following fields of JobEntry must be initialized before this call:
  119.       TargetServerID   - use -1 to indicate "any server"
  120.       TargetExecTime   - fill with $FF to indicate "first opportunity"
  121.       JobControlFlags  - See the jcfXXX constants in NETQUE.PAS
  122.       TextJobDesc      - Asciiz string text description of print job
  123.   }
  124.  
  125. implementation
  126.  
  127. {$IFDEF WindowsOrDPMI}
  128.   {$I NETPRNQW.INC}
  129. {$ELSE}
  130.   {$I NETPRNQU.INC}
  131. {$ENDIF}
  132.  
  133. procedure MakeClientRecord(pTabSize : Byte; pNumCopies : Word; pFlags : Byte;
  134.                            pLinesPerPage : Word; pColsPerPage : Word;
  135.                            pBannerName : Str20; pUserName : String;
  136.                            var ClientArea : ClientRecordArea);
  137. const
  138.   UnknownConst : Array[0..21] of Char = 'UNKNOWN'#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0;
  139.  
  140. var
  141.   Client : TPrintQueClientRec absolute ClientArea;
  142. begin
  143.   FillChar(ClientArea, SizeOf(ClientArea), 0);
  144.   with Client do begin
  145.     TabSize := pTabSize;
  146.     NumCopies := Swap(pNumCopies);
  147.     Flags := pFlags;
  148.     if pLinesPerPage = 0 then
  149.       LinesPerPage := Swap(DefaultLPP)
  150.     else
  151.       LinesPerPage := Swap(pLinesPerPage);
  152.     if pColsPerPage = 0 then
  153.       ColsPerPage := Swap(DefaultCPP)
  154.     else
  155.       ColsPerPage := Swap(pColsPerPage);
  156.     Move(UnknownConst, Unknown, SizeOf(Unknown));
  157.     if Length(pBannerName) > 13 then
  158.       Byte(pBannerName[0]) := 13;
  159.     Move(pBannerName[1], BannerName, Length(pBannerName));
  160.     if Length(pUserName) > 13 then
  161.       Byte(pUserName[0]) := 13;
  162.     Move(pUserName[1], UserName, Length(pUserName));
  163.   end;
  164. end;
  165.  
  166. function AddFileToPrintQueue(QueueID : LongInt;
  167.                              var JobEntry : JobEntryType;
  168.                              FName : String) : Byte;
  169. const
  170.   BufferSize = 8192;
  171. var
  172.   NumRead : Word;
  173.   Buffer : Pointer;
  174.   InF, F : File;
  175.   Result : Byte;
  176. begin
  177.   GetMem(Buffer, BufferSize);
  178.   if Buffer = Nil then begin
  179.     AddFileToPrintQueue := 8;
  180.     Exit;
  181.   end;
  182.   Assign(InF, FName);
  183.   Reset(InF, 1);
  184.   Result := IoResult;
  185.   if Result = 0 then begin
  186.     Result := CreateQueueJobAndFile(QueueID, JobEntry, JobEntry);
  187.     if Result = 0 then begin
  188.       Assign(F, 'NETQ');
  189.       Rewrite(F, 1);
  190.       Result := IoResult;
  191.       while (Result = 0) and (not EOF(InF)) do begin
  192.         BlockRead(InF, Buffer^, BufferSize, NumRead);
  193.         Result := IoResult;
  194.         if Result = 0 then begin
  195.           BlockWrite(F, Buffer^, NumRead);
  196.           Result := IoResult;
  197.         end;
  198.       end;
  199.       Close(F);
  200.       if Result = 0 then begin
  201.         Result := IoResult;
  202.         Result := CloseFileAndStartJob(QueueID, Swap(JobEntry.JobNumber));
  203.       end
  204.       else begin
  205.         if IoResult <> 0 then ;
  206.         if AbortServicingQueueJob(QueueID, Swap(JobEntry.JobNumber)) <> 0 then ;
  207.       end;
  208.     end;
  209.     Close(InF);
  210.     if IoResult <> 0 then ;
  211.   end;
  212.   FreeMem(Buffer, BufferSize);
  213.   AddFileToPrintQueue := Result;
  214. end;
  215.  
  216. end.
  217.  
  218.